package com.imay.live.activity.family.controller;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imay.live.R;
import com.imay.live.activity.family.FamilyLevelDesActivity;
import com.imay.live.manager.FamilyAccountManager;
import com.imay.live.model.FamilyExpsBean;
import com.imay.live.model.FamilyModel;
import com.imay.live.utils.ViewUtil;
import com.imay.live.view.ViewFamilyProgress;

import java.util.Map;

/**
 * Created by Administrator on 2017/9/13 0013.
 */

public class FamilyLevelController extends BaseFamilyController {

    TextView tv_family_level, tv_user_level_descript;
    LinearLayout ll_family_level_permission;
    ViewFamilyProgress vfp_family_level;

    @Override
    protected void initView() {
        tv_family_level = ViewUtil.findView(activity, R.id.tv_family_level);
        ll_family_level_permission = ViewUtil.findView(activity, R.id.ll_family_level_permission);
        tv_user_level_descript = ViewUtil.findView(activity, R.id.tv_user_level_descript);
        vfp_family_level = ViewUtil.findView(activity, R.id.vfp_family_level);

        ll_family_level_permission.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FamilyLevelDesActivity.startActivity(activity);
            }
        });
    }

    public void setFamilyData(FamilyModel familyData) {
        Map<Integer, FamilyExpsBean> map = FamilyAccountManager.getInstance().getFamilyExps();
        tv_family_level.setText(String.valueOf(familyData.getLv()));
        if (familyData.getLv() >= 30) {
            vfp_family_level.setMaxLevel();
            vfp_family_level.setNowLevel(familyData.getLv() - 1);
            vfp_family_level.setNextLevel(familyData.getLv());
        } else {
            vfp_family_level.setNowLevel(familyData.getLv());
            vfp_family_level.setNextLevel(familyData.getLv() + 1);
        }
        if (map.containsKey(familyData.getLv())) {
            FamilyExpsBean expsBean = map.get(familyData.getLv());
            vfp_family_level.setContribution(familyData.getContribution(), expsBean.getExp());
            tv_user_level_descript.setText(expsBean.getVip());
        }
    }
}
